package job.wl;

import java.util.Arrays;
import java.util.Stack;

/**
 * Author: Zhang Dongwei
 * Date: 2023/8/23 17:27
 */
public class wl {
    public static void main(String args[]) {
        String s = "([]{})}";
//        String s = "{}";
        boolean flag = false;
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++){
            if (s.charAt(i) == '[' || s.charAt(i) == '(' || s.charAt(i) == '{'){
                stack.push(s.charAt(i));
            }else if (s.charAt(i) == ']'){
                if (!stack.isEmpty() && stack.pop() != '[')
                {
                    flag = false;
                    break;
                }
            }else if (!stack.isEmpty() && s.charAt(i) == '}'){
                if (stack.pop() != '{'){
                    flag = false;
                    break;
                }
            }else if (!stack.isEmpty() && s.charAt(i) == ')'){
                if (stack.pop() != '(')
                {
                    flag = false;
                    break;
                }
            }
        }
        if (stack.isEmpty()) flag = true;
        System.out.println(flag);
    }
}
